package com.hcb.tonguetiphealth.view;

import android.os.Bundle;

import com.hcb.tonguetiphealth.global.Global;
import com.hcb.tonguetiphealth.manager.Exit;
import com.hcb.tonguetiphealth.widget.homepage.LoginWidget;

public class LoginActivity extends AbstractActivity {
	private static final String TAG = "LoginActivity";
	private static final String url_acceptChat = Global.URL + Global.servlet_acceptChat;
	private static final String url_refuseChat = Global.URL + Global.servlet_refuseChat;
	
	  String name = "";
	  String chatId = "";
	  String time = "";
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      
     /* String from = getIntent().getStringExtra("from");
      if(from != null && from.equals("TongueTipHealthService")) {
    	  getIntent().putExtra("from", "");
    	  name = getIntent().getStringExtra("name");
    	  chatId = getIntent().getStringExtra("chatId");
    	  time = getIntent().getStringExtra("time");
    	  acceptOrRefuseChatDialog();
    	  
    	  NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);  
          manager.cancel(TongueTipHealthService.ID_NOTIFICATION);
      }
      */
      setContentView(new LoginWidget(this));
      
      Exit.add(this);
  }
  
/*  private void acceptOrRefuseChatDialog() {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle("聊天请求");
		//builder.setIcon(R.drawable.what);
		builder.setMessage(name + "向你发起聊天");
		builder.setCancelable(false);
		builder.setPositiveButton("拒绝", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				acceptOrRefuseChat(2);
			}
		});
		builder.setNegativeButton("同意", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int id) {
				acceptOrRefuseChat(1);
				//dialog.cancel();
			}
		});
		builder.show();
	}

	private void acceptOrRefuseChat(final int flag) {
		new Thread() {
			public void run() {
				String response = null;
				  String url = flag==1? url_acceptChat : url_refuseChat;
					try {
						List <NameValuePair> params = new ArrayList <NameValuePair>();
						params.add(new BasicNameValuePair("chatId", chatId));
						params.add(new BasicNameValuePair("userName", Global.user==null? "":Global.user.getUserName()));
						params.add(new BasicNameValuePair("tagName", name));
						
						response = HttpUtils.Post(url, params);
						
						if(Global.DEBUG) {
							System.out.println("acceptOrRefuseChat -----------------------------\n" + response);
						}
					} catch(Exception e) {
						Log.e(TAG, "Exception", e);
					}
					if(!StringUtils.isEmpty(response)) {
						JSONManager jManager = new JSONManager();
						boolean isGotJSONObject = jManager.isGotJSONObject(response);
						if(isGotJSONObject) {
							int count = jManager.getResult();
							String msg = jManager.getMsg();
							System.out.println("------ 得到msg: " + count + ":" + msg);
						}
					}
			}
		}.start();
	}*/

	@Override
	public void onBackPressed() {
		finish();
	}
	
	/*@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		String picPath = null;
		if (resultCode == Activity.RESULT_OK) {  
			if(requestCode == MessageWhat.PICTURE) {
				Uri uri = data.getData();  
	            Cursor cursor = this.getContentResolver().query(uri, null, null, null, null);  
	            cursor.moveToFirst();  
	            for (int i = 0; i < cursor.getColumnCount(); i++) {// 取得图片uri的列名和此列的详细信息  
	            	if(i == 1) {
	            		picPath = cursor.getString(i);
	            	}
	                System.out.println(i + " ------- " + cursor.getColumnName(i) + " --- " + cursor.getString(i));  
	            } 
	            if(mHandler != null) {
	            	Message msg = mHandler.obtainMessage(MessageWhat.PICTURE);
	            	msg.obj = picPath;
	            	msg.sendToTarget();
	            }
			}
        }  
		//super.onActivityResult(requestCode, resultCode, data);
	}*/

}